
var animationTarget : Animation;
var maxForwardSpeed : float = 6;

var character : CharacterController;
var thisTransform : Transform;

function Start () {
	Debug.Log("Starting controller");
	character = GetComponent(CharacterController);
	thisTransform = transform;
	
	animationTarget.wrapMode = WrapMode.Loop;
	//animationTarget["picotea"].wrapMode = WrapMode.ClampForever;
	
	
}

function Update() {
	var characterVelocity = character.velocity;
	var horizontalVelocity : Vector3 = characterVelocity;
	horizontalVelocity.y = 0;
	var speed = horizontalVelocity.magnitude;
	
	// Debug.Log("Speed: " + speed);
	
	var forwardMotion = Vector3.Dot( this.transform.forward, horizontalVelocity);
	
	// Debug.Log("Forward: " + forwardMotion);
	
	var t = 0.0;
	if (forwardMotion > 0) {
		//t = Mathf.Clamp( Mathf.Abs( speed / maxForwardSpeed ), 0, maxForwardSpeed );
		//Debug.Log("AnimationSpeed: " + animationTarget["camina"].speed);
		//animationTarget["camina"].speed = Mathf.Lerp( 0.25, 1, t );
		animationTarget.CrossFade("camina");
	}
	else {
		animationTarget.CrossFade("picotea");
	}
}

function OnEndGame() {
	this.enabled = false;
}